package com.ruoyi.project.system.business.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.PageQuery;
import com.ruoyi.framework.web.page.TableData;
import com.ruoyi.project.system.joinus.domain.Joinus;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.business.mapper.BusinessMapper;
import com.ruoyi.project.system.business.domain.Business;
import com.ruoyi.project.system.business.service.IBusinessService;
import com.ruoyi.common.utils.text.Convert;

/**
 * businessService业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-18
 */
@Service
public class BusinessServiceImpl implements IBusinessService 
{
    @Autowired
    private BusinessMapper businessMapper;

    /**
     * 查询business
     * 
     * @param id business主键
     * @return business
     */
    @Override
    public Business selectBusinessById(Long id)
    {
        return businessMapper.selectById(id);
    }

    /**
     * 查询business列表
     * 
     * @param business business
     * @return business
     */
    @Override
    public TableData<Business> selectBusinessList(Business business, PageQuery pageQuery)
    {
        LambdaQueryWrapper<Business> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNoneBlank(business.getPersonName()), Business::getPersonName,business.getPersonName())
                .like(StringUtils.isNoneBlank(business.getTelphone()), Business::getTelphone,business.getTelphone())
                .like(StringUtils.isNoneBlank(business.getCompanyName()), Business::getCompanyName,business.getCompanyName());
        Page<Business> page = businessMapper.selectPage(pageQuery.build(), lqw);
        return TableData.build(page);
    }

    /**
     * 新增business
     * 
     * @param business business
     * @return 结果
     */
    @Override
    public int insertBusiness(Business business)
    {
        business.setCreateTime(DateUtils.getNowDate());
        return businessMapper.insert(business);
    }

    /**
     * 修改business
     * 
     * @param business business
     * @return 结果
     */
    @Override
    public int updateBusiness(Business business)
    {
        business.setUpdateTime(DateUtils.getNowDate());
        return businessMapper.updateById(business);
    }

    /**
     * 批量删除business
     * 
     * @param ids 需要删除的business主键
     * @return 结果
     */
    @Override
    public int deleteBusinessByIds(String ids)
    {
        List<String> collect = Arrays.stream(ids.split(",")).collect(Collectors.toList());
        return businessMapper.deleteBatchIds(collect);
    }

    /**
     * 删除business信息
     * 
     * @param id business主键
     * @return 结果
     */
    @Override
    public int deleteBusinessById(Long id)
    {
        return businessMapper.deleteById(id);
    }
}
